import model
from google.appengine.ext import db
from google.appengine.ext import webapp

class DataClear(webapp.RequestHandler):
    def get(self):
        q = db.GqlQuery("SELECT * FROM SearchResult") 
        results = q.fetch(200)
        num = len(results)
        if num > 0:
            db.delete(results)
            self.response.out.write('<html><body>')
            self.response.out.write( str(num) + " data clear")
            self.response.out.write('</body></html>')
            #self.response.out.write('<html><head><script>function reload(){ document.location = ')
            #self.response.out.write("'/clear?time=' + new Date().getTime() } setTimeout('reload()', 1000); </script>")
            #self.response.out.write('</head><body></body></html>')
        if num == 0:
            self.response.out.write('<html><body>')
            self.response.out.write("Data clear")
            self.response.out.write('</body></html>')
        '''
        while len(results) > 0: 
            db.delete(results)    
            q = db.GqlQuery("SELECT * FROM SearchResult")
            results = q.fetch(500)
        '''


